package com.mou.service.impl;

import com.mou.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service("emailService")
public class EmailServiceImpl implements EmailService {
    @Autowired
    private JavaMailSender mailSender;
    @Value("${spring.mail.username}")
    private String from;

    public void sendCaptchaEmail(String to, String code) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSubject("[校园二手街] 注册验证码");
        message.setText(String.format("您的验证码为：%s\n" +
                "            该验证码5分钟内有效，请勿泄露给他人\n" +
                "            如非本人操作，请忽略此邮件", code));
        mailSender.send(message);
    }

}
